<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Connect events from a COM object to a PHP object</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.com-create-guid.html">com_create_guid</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.com-get-active-object.html">com_get_active_object</a></div>
 <div class="up"><a href="ref.com.html">COM 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.com-event-sink" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">com_event_sink</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.2.0, PHP 5)</p><p class="refpurpose"><span class="refname">com_event_sink</span> &mdash; <span class="dc-title">Connect events from a COM object to a PHP object</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.com-event-sink-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>com_event_sink</strong></span>
    ( <span class="methodparam"><span class="type"><a href="class.variant.html" class="type variant">variant</a></span> <code class="parameter">$comobject</code></span>
   , <span class="methodparam"><span class="type">object</span> <code class="parameter">$sinkobject</code></span>
   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$sinkinterface</code></span>
  ] )</div>

  <p class="para rdfs-comment">
   Instructs COM to sink events generated by
   <em><code class="parameter">comobject</code></em> into the PHP object
   <em><code class="parameter">sinkobject</code></em>.
  </p>
  <p class="para">
   Be careful how you use this feature; if you are doing something similar
   to the example below, then it doesn&#039;t really make sense to run it in a
   web server context.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.com-event-sink-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">comobject</code></em></dt>

     <dd>

      <p class="para">
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">sinkobject</code></em></dt>

     <dd>

      <p class="para">
       <em><code class="parameter">sinkobject</code></em> should be an instance of a class with
       methods named after those of the desired dispinterface; you may use
       <span class="function"><a href="function.com-print-typeinfo.html" class="function">com_print_typeinfo()</a></span> to help generate a template class
       for this purpose.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">sinkinterface</code></em></dt>

     <dd>

      <p class="para">
       PHP will attempt to use the default dispinterface type specified by
       the typelibrary associated with <em><code class="parameter">comobject</code></em>, but
       you may override this choice by setting
       <em><code class="parameter">sinkinterface</code></em> to the name of the dispinterface
       that you want to use.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.com-event-sink-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.com-event-sink-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5241">
    <p><strong>Example #1 COM event sink example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">IEEventSinker&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;</span><span style="color: #0000BB">$terminated&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">ProgressChange</span><span style="color: #007700">(</span><span style="color: #0000BB">$progress</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$progressmax</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Download&nbsp;progress:&nbsp;</span><span style="color: #0000BB">$progress</span><span style="color: #DD0000">&nbsp;/&nbsp;</span><span style="color: #0000BB">$progressmax</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">DocumentComplete</span><span style="color: #007700">(&amp;</span><span style="color: #0000BB">$dom</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$url</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Document&nbsp;</span><span style="color: #0000BB">$url</span><span style="color: #DD0000">&nbsp;complete\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">OnQuit</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Quit!\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">terminated&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></span><span style="color: #0000BB">$ie&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">COM</span><span style="color: #007700">(</span><span style="color: #DD0000">"InternetExplorer.Application"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//&nbsp;note&nbsp;that&nbsp;you&nbsp;don't&nbsp;need&nbsp;the&nbsp;&amp;&nbsp;for&nbsp;PHP&nbsp;5!<br /></span><span style="color: #0000BB">$sink&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">IEEventSinker</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">com_event_sink</span><span style="color: #007700">(</span><span style="color: #0000BB">$ie</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sink</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"DWebBrowserEvents2"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$ie</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">Visible&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$ie</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">Navigate</span><span style="color: #007700">(</span><span style="color: #DD0000">"http://www.example.org"</span><span style="color: #007700">);<br />while(!</span><span style="color: #0000BB">$sink</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">terminated</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;</span><span style="color: #0000BB">com_message_pump</span><span style="color: #007700">(</span><span style="color: #0000BB">4000</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">$ie&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">null</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.com-event-sink-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.com-print-typeinfo.html" class="function" rel="rdfs-seeAlso">com_print_typeinfo()</a> - Print out a PHP class definition for a dispatchable interface</span></li>
    <li class="member"><span class="function"><a href="function.com-message-pump.html" class="function" rel="rdfs-seeAlso">com_message_pump()</a> - Process COM messages, sleeping for up to timeoutms milliseconds</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.com-create-guid.html">com_create_guid</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.com-get-active-object.html">com_get_active_object</a></div>
 <div class="up"><a href="ref.com.html">COM 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
